Repository navigation
fix: prevent dpr override for FileUrl icons - #762
Merged
Merged
Conversation
Reviewer's GuideImplementationAdd a FileUrl guard to DTK DPR refreshes and delegate FileUrl DPR updates to Qt Quick, preserving DTK scaling for other icon types.
Use the guarded DPR refresh at icon initialization, lifecycle, pixmap, and Dci player update points.
TestsExercise FileUrl DPR preservation and verify SVG icons still use DTK DPR updates.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/private/dquickiconimage.cpp" line_range="27-28" />
<code_context>
+bool DQuickIconImagePrivate::refreshDtkDevicePixelRatio()
+{
+ if (iconType == FileUrl)
+ return false;
+
+ return updateDevicePixelRatio(1.0);
+}
+
bool DQuickIconImagePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio)
{
+ if (iconType == FileUrl)
+ return QQuickImagePrivate::updateDevicePixelRatio(targetDevicePixelRatio);
+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
</code_context>
<issue_to_address>
**Raster fallbacks still lose native lookup**
When a theme icon fails to load and its `fallbackSource` is a raster file with `@Nx` variants, a theme icon that fails and falls back to a raster `fallbackSource` keeps `iconType` as `ThemeIconName`; the new guard therefore continues DTK DPR handling for that active file source, overriding Qt Quick’s native `@Nx` handling.
Apply the native DPR path based on the active fallback source, or mark local file fallbacks as `FileUrl` while they are active.
</issue_to_address>
### Comment 2
<location path="src/private/dquickiconimage.cpp" line_range="27-28" />
<code_context>
+bool DQuickIconImagePrivate::refreshDtkDevicePixelRatio()
+{
+ if (iconType == FileUrl)
+ return false;
+
+ return updateDevicePixelRatio(1.0);
+}
+
bool DQuickIconImagePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio)
{
+ if (iconType == FileUrl)
+ return QQuickImagePrivate::updateDevicePixelRatio(targetDevicePixelRatio);
+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
</code_context>
<issue_to_address>
**Local SVGs lose DTK scaling**
When an icon is a local SVG file URL, `refreshDtkDevicePixelRatio()` returns before calculating the DTK ratio, and `updateDevicePixelRatio()` delegates to Qt Quick; local SVG icons therefore stop using the DTK DPR calculation and can render at the wrong size.
Distinguish local SVGs from raster file sources in both DPR paths so SVGs retain DTK scaling while raster files use Qt Quick’s native handling.
Also at `src/private/dquickiconimage.cpp:20`.
</issue_to_address>
### Comment 3
<location path="tests/ut_dquickiconimage.cpp" line_range="74-76" />
<code_context>
+ EXPECT_FALSE(icon.d_func()->refreshDtkDevicePixelRatio());
+ EXPECT_DOUBLE_EQ(icon.d_func()->devicePixelRatio, decodedDpr);
+
+ // A raster file lets Qt Quick continue to its @Nx lookup.
+ EXPECT_FALSE(icon.d_func()->updateDevicePixelRatio(1.25));
+ EXPECT_DOUBLE_EQ(icon.d_func()->devicePixelRatio, decodedDpr);
+
+ icon.setName(QStringLiteral("qrc:/icon/red.svg"));
</code_context>
<issue_to_address>
**Native @Nx lookup goes untested**
When the test is used to validate native `@Nx` lookup, the test seeds `devicePixelRatio` and calls the private update method without loading an image or checking the selected or rendered variant, so it passes even if the override never delegates to Qt Quick and native `@Nx` lookup is broken.
Load a raster image with `@Nx` variants and assert which variant Qt Quick actually selects or renders.
</issue_to_address>
### Comment 4
<location path="tests/ut_dquickiconimage.cpp" line_range="78" />
<code_context>
+ EXPECT_FALSE(icon.d_func()->updateDevicePixelRatio(1.25));
+ EXPECT_DOUBLE_EQ(icon.d_func()->devicePixelRatio, decodedDpr);
+
+ icon.setName(QStringLiteral("qrc:/icon/red.svg"));
+ EXPECT_TRUE(icon.d_func()->updateDevicePixelRatio(1.0));
+ EXPECT_DOUBLE_EQ(icon.d_func()->devicePixelRatio, 1.0);
</code_context>
<issue_to_address>
**Theme DPR branch stays untested**
When the test uses a `qrc:` SVG URL as its purported theme-icon case, `fileUrlIgnoresWindowDprRefresh` sets another `qrc:` URL at line 78, so `setName()` classifies it as `FileUrl`; the assertion at line 79 then exercises the Qt Quick delegation branch, not DTK's theme-icon DPR calculation.
Use a theme icon name that is not a local URL to exercise the DTK DPR branch.
</issue_to_address>
1. Add refreshDtkDevicePixelRatio() wrapper in DQuickIconImagePrivate that returns false early when iconType is FileUrl 2. Update updateDevicePixelRatio() override to delegate to QQuickImagePrivate::updateDevicePixelRatio() for FileUrl icons instead of forcing DTK pixel ratio logic 3. Replace direct calls to updateDevicePixelRatio(1.0) with refreshDtkDevicePixelRatio() in DQuickIconImage::init(), componentComplete(), itemChange(), pixmapChange(), and DQuickDciIconImageItemPrivate::updatePlayer() 4. Update unit test includes to reference the private header and add a new test verifying FileUrl icons preserve the decoded DPR and delegate to Qt Quick's native @nx lookup The DTK pixel ratio logic was incorrectly overriding Qt Quick's native device pixel ratio handling for raster file icons, which broke the ability of Qt Quick to perform @nx file lookup. FileUrl icons now bypass the DTK override and use the base QQuickImagePrivate implementation, while theme/svg icon paths retain the previous behavior. Influence: 1. Verify raster image icons (FileUrl) load correct @nx variants on high-DPI displays 2. Confirm theme name and SVG icons still honor the DTK device pixel ratio calculation 3. Test window change and device pixel ratio change events update icon rendering correctly for both FileUrl and theme icons 4. Run the new ut_DQuickIconImage.fileUrlIgnoresWindowDprRefresh unit test 5. Validate DciIcon images under treeland still refresh their device pixel ratio on player update fix: 修复 FileUrl 图标设备像素比被错误覆盖的问题 1. 在 DQuickIconImagePrivate 中新增 refreshDtkDevicePixelRatio() 包装函 数,当 iconType 为 FileUrl 时提前返回 false 2. 修改 updateDevicePixelRatio() 重写实现,对 FileUrl 图标改为调用基类 QQuickImagePrivate::updateDevicePixelRatio(),不再强制执行 DTK 像素比 逻辑 3. 在 DQuickIconImage::init()、componentComplete()、itemChange()、 pixmapChange() 以及 DQuickDciIconImageItemPrivate::updatePlayer() 中,将 直接调用 updateDevicePixelRatio(1.0) 替换为 refreshDtkDevicePixelRatio() 4. 更新单元测试的私有头文件引用,新增测试用例验证 FileUrl 图标保持解码后 的 DPR 并能委托给 Qt Quick 原生 @nx 查找 此前 DTK 的像素比逻辑会错误地覆盖 Qt Quick 对栅格文件图标的原生设备像素 比处理,导致 Qt Quick 无法执行 @nx 文件查找。现在 FileUrl 图标会绕过 DTK 覆盖逻辑并使用基类 QQuickImagePrivate 实现,而主题/SVG 图标路径保持原有 行为。 Influence: 1. 验证栅格图像图标(FileUrl)在高 DPI 屏幕上能正确加载 @nx 变体 2. 确认主题名称和 SVG 图标仍遵循 DTK 设备像素比计算 3. 测试窗口变化和设备像素比变化事件对 FileUrl 及主题图标的渲染更新是否 正确 4. 运行新增的 ut_DQuickIconImage.fileUrlIgnoresWindowDprRefresh 单元测试 5. 验证 treeland 下 DciIcon 图像在播放器更新时仍会刷新其设备像素比 Log: Fixed device pixel ratio being incorrectly overridden for FileUrl icons PMS: BUG-381363
mhduiy
approved these changes
Dec 3, 2026
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, mhduiy The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
that returns false early when iconType is FileUrl
QQuickImagePrivate::updateDevicePixelRatio() for FileUrl icons instead
of forcing DTK pixel ratio logic
refreshDtkDevicePixelRatio() in DQuickIconImage::init(),
componentComplete(), itemChange(), pixmapChange(), and
DQuickDciIconImageItemPrivate::updatePlayer()
new test verifying FileUrl icons preserve the decoded DPR and delegate
to Qt Quick's native @nx lookup
The DTK pixel ratio logic was incorrectly overriding Qt Quick's native
device pixel ratio handling for raster file icons, which broke the
ability of Qt Quick to perform @nx file lookup. FileUrl icons now bypass
the DTK override and use the base QQuickImagePrivate implementation,
while theme/svg icon paths retain the previous behavior.
Influence:
high-DPI displays
ratio calculation
rendering correctly for both FileUrl and theme icons
test
pixel ratio on player update
fix: 修复 FileUrl 图标设备像素比被错误覆盖的问题
数,当 iconType 为 FileUrl 时提前返回 false
QQuickImagePrivate::updateDevicePixelRatio(),不再强制执行 DTK 像素比
逻辑
pixmapChange() 以及 DQuickDciIconImageItemPrivate::updatePlayer() 中,将
直接调用 updateDevicePixelRatio(1.0) 替换为 refreshDtkDevicePixelRatio()
的 DPR 并能委托给 Qt Quick 原生 @nx 查找
此前 DTK 的像素比逻辑会错误地覆盖 Qt Quick 对栅格文件图标的原生设备像素
比处理,导致 Qt Quick 无法执行 @nx 文件查找。现在 FileUrl 图标会绕过 DTK
覆盖逻辑并使用基类 QQuickImagePrivate 实现,而主题/SVG 图标路径保持原有
行为。
Influence:
正确
Log: Fixed device pixel ratio being incorrectly overridden for FileUrl
icons
PMS: BUG-381363
Summary by Sourcery
Keep raster FileUrl icons on Qt Quick’s native device-pixel-ratio path without changing DTK scaling for theme and SVG icons.
Bug Fixes:
Tests: